//
//  SZVisitorViewController.m
//  Weibo
//
//  Created by Zahi on 2017/7/23.
//  Copyright © 2017年 Zahi. All rights reserved.
//

#import "SZVisitorViewController.h"
#import "SZVisitorView.h"
#import "SZOAuthViewController.h"
#import "SZNavigationController.h"
#import "SZAccountViewModel.h"

@interface SZVisitorViewController ()

@end

@implementation SZVisitorViewController
#pragma mark - 初始化
- (instancetype)init
{
    if (self = [super init]) {
    }
    
    return  self;
}


- (BOOL)isLogin
{
    return [SZAccountViewModel shared].isLogin;
}



#pragma mark - 设置view
- (void)loadView
{
    
    if (self.isLogin) {
        
        [super loadView];
        
    } else {
        // 设置导航控制器
        [self setupNav];
        
        _visitorView = [SZVisitorView new];
        
        
        __weak typeof(self) weakSelf = self;
        _visitorView.visitorViewBlock = ^{
            [weakSelf enterLoginPage];
        };

        self.view = _visitorView;
    }
}


#pragma mark - 设置导航控制器
- (void)setupNav {
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithTitle:@"注册" image:nil target:self action:@selector(registerItemAction)];
    
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItemWithTitle:@"登录" image:nil target:self action:@selector(loginItemAction)];
}


#pragma mark - 监听按钮的点击
- (void)registerItemAction {
    NSLog(@"注册");
    [self enterLoginPage];
}

- (void)loginItemAction {
    NSLog(@"登录");
    
    [self enterLoginPage];
}


#pragma mark - 进入登录页面
- (void)enterLoginPage
{
    SZOAuthViewController *OAuthVc = [SZOAuthViewController new];
    
    SZNavigationController *nav = [[SZNavigationController alloc] initWithRootViewController:OAuthVc];
    
    [self presentViewController:nav animated:YES completion:nil];
    
    
}

@end
